/**
 *学生基本信息管理模块
 **/
$(function () {
    //学部列表
    $('#manager-review').datagrid({
        url: Think.APP + "Review/index&cmd=InfoReview", //数据源
        fit: true, //自适应
        striped: true,
        fitColumns: true,
        toolbar: '#review-toolbar',
        border: false, //取消边框
        pagination: true, //分页开启
        pageSize: 50,
        rownumbers: true,
        columns: [[
            { title: 'ID', field: '', checkbox: true },
            { field: 'title', title: '题目', width: 100, align: 'center' },
            { field: 'count', title: '答卷人数', width: 100, align: 'center' },
            {
                field: 'action', title: '操作', width: 100, align: 'center', formatter: function (value, rec) {
                    var btn = '<a class="user_action" onclick="review_toolbar.view(\'' + rec.title + '\')" href="javascript:void(0)">查看统计报表</a>';
                    return btn;
                }
            }
        ]],
        onClickRow: function (rowIndex, rowData) {//单击事件
            $('#manager-review').datagrid("clearChecked"); //取消所有行的选中
            $('#manager-review').datagrid("selectRow", rowIndex);  //选中当前行
        },
        onDblClickRow: function (field, row) {

        },
        onLoadSuccess: function (data) {
            $('.user_action').linkbutton({ text: '查看统计报表', plain: true, iconCls: 'icon-edit' });
        },
    });


    //显示添加框
    $('#view-main').window({
        title: '统计报表',
        width: 800,
        height: 500,
        closed: true,
        modal: true //遮罩层
    });

    //添加方法
    review_toolbar = {
        view: function (result_title) {
            //弹出dialog
            $('#view-main').window("open");//开启
            var myChart = echarts.init(document.getElementById('view-main-echarts'));
            var option = {
                title: {
                    text: result_title+"问卷统计分析",
                    subtext: '文华学院教务处',
                    x: 'center'
                },
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    orient: 'vertical',
                    left: 'left',
                    top:'30px',
                    data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
                },
                series: [
                    {
                        name: '问卷统计分析',
                        type: 'pie',
                        radius: '55%',
                        center: ['50%', '60%'],
                        data: [
                            { value: 335, name: '直接访问' },
                            { value: 310, name: '邮件营销' },
                            { value: 234, name: '联盟广告' },
                            { value: 135, name: '视频广告' },
                            { value: 1548, name: '搜索引擎' }
                        ],
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
           
            //请求加载数据
            $.ajax({
                url: Think.APP + "Review/view",
                type: 'post',
                data: {'title':result_title},
                success: function (data) {
                    
                    if (data.success == 1) {
                        console.log(data);
                        option.series[0].data = data.data.data;
                        option.legend.data = data.data.field;
                        myChart.setOption(option);
                    }
                }
            });
             $(window).resize(function () {
                myChart.resize();
            });
            $('#view-main').resize(function () {
                myChart.resize();
            });
        }
    };

});